﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Base.Entity;

namespace T.FAS.Runtime.ScheduleJob.SPI
{
    /// <summary>
    /// 计划任务订阅
    /// </summary>
    public class ScheduleJobSubscription
    {
        public ScheduleJobSubscription()
        {
            if (string.IsNullOrEmpty(ID))
                ID = Guid.NewGuid().ToString();
            if (string.IsNullOrEmpty(ScheduleJobInstanceID))
                ScheduleJobInstanceID = Guid.NewGuid().ToString();
        }
        public string ID { get; set; }
        public string Code{ get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        /// <summary>
        /// 订阅来源类型
        /// </summary>
        public SubscriptionSourceType SourceType { get; set; }
        public string SourceID { get; set; }
        public string SourceName { get; set; }
        public bool IsEnable { get; set; }
        public string ScheduleJobInstanceID { get; set; }
        public string OwnerID { get; set; }
        public string OwnerName { get; set; }
        /// <summary>
        /// 可执行的低代码脚本
        /// </summary>
        public string JSContent { get; set; }
        /// <summary>
        /// 可执行的低代码脚本参数信息
        /// </summary>
        public string JSContentParams { get; set; }
        /// <summary>
        /// 查询元数据标识：与JSContent搭配使用，用于对JSContent的返回数据进行结构化解析处理
        /// </summary>
        public string ReturnDataType { get; set; }
        /// <summary>
        /// 是否是基础数据类型：String,Int,Boolean等，非基础类型的指的是低代码中的各种元数据：DO、EO、CDO等
        /// </summary>
        public bool IsBasic { get; set; }
        /// <summary>
        /// 数据类型：主要用DataType中的Record和List两个，用于标识是集合还是单个
        /// </summary>
        public DataType ReturnType { get; set; }

        /// <summary>
        /// 原始的订阅数据信息,可用于后续补充生成计划任务
        /// </summary>
        public string OriginalData { get; set; }
        /// <summary>
        /// 业务类型：基于该字段进行多实例的部署
        /// </summary>
        public string BusinessType { get; set; }
        /// <summary>
        /// 业务类型名称：与BusinessType搭配使用
        /// </summary>
        public string BusinessName { get; set; }
        public string LinkUrl { get; set; }
        /// <summary>
        /// 通知触发条件
        /// </summary>
        public TriggerType TriggerType { get; set; }
        /// <summary>
        /// 复杂通知触发条件定义
        /// </summary>
        public string ComplexTriggerCondition { get; set; }
        public ScheduleJobSubscriptionTriggerCondition ComplexTriggerConditionView
        {
            get
            {
                if (!string.IsNullOrEmpty(ComplexTriggerCondition))
                {
                    return JsonConvert.DeserializeObject<ScheduleJobSubscriptionTriggerCondition>(ComplexTriggerCondition);
                }
                return null;
            }
        }
        public List<ScheduleJobSubscriptionNoticeSet> NoticeSets { get; set; }
        public ScheduleJobSubscriptionFrequency ExecuteFrequency { get; set; }
        public string Ext1 { get; set; }
        public string Ext2 { get; set; }
        public string Ext3 { get; set; }
        public string TenantID { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; }
        public string LastModifier { get; set; }
        public DateTime LastModifyTime { get; set; }
    }
}
